package com.sinodata.bsm.center.engine.event;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.log4j.Logger;

import com.sinodata.bsm.center.bean.EventRuleBean;
import com.sinodata.bsm.common.vo.Event;

/**
 * 
 * <p>
 * Description: 不可恢复事件规则组
 * </p>
 *
 * @author liulibo
 * @version 1.0

 * <p>
 * History: 
 *
 * Date                     Author         Version     Description
 * ---------------------------------------------------------------------------------
 * 2012-5-24 PM 1:17:41     liulibo        1.0         To create
 * </p>
 *
 * @since 
 * @see
 */
public class UnresumableRuleGroup extends EventRuleGroup {

    protected static Logger logger = Logger.getLogger(UnresumableRuleGroup.class);

    /**
     * @param resId
     * @param typeId
     */
    public UnresumableRuleGroup(Long resId, Long typeId) {
        super(resId, typeId);
    }

    /*
     * (non-Javadoc)
     * @see com.sinodata.bsm.center.engine.event.EventRuleGroup#matches(java.lang.Long, java.lang.Long)
     */
    @Override
    public List<Event> matches(Long resId, Long propId) {
        List<Event> events = new ArrayList<Event>();
        Event hevent = null;
        for (Iterator<EventRuleBean> i = rules.iterator(); i.hasNext();) {
            EventRuleBean r = i.next();
            if (r.matching()) {
                try {
                    Event newEvent = r.makeEvent(null);
                    if (hevent == null || hevent.getLevel() < newEvent.getLevel()) {
                        hevent = newEvent;
                    }
                } catch (Exception e) {
                    logger.error("failed to create event ", e);
                }
            }
        }
        if (hevent != null) {
            events.add(hevent);
        }
        return events;
    }

}